import os
from shutil import copyfile

input_1 = 'D:/dataset/CASIA-ROI'
out_train = 'D:/PycharmProject/PalmROI/data/Datasets/CASIA/train'
out_test = 'D:/PycharmProject/PalmROI/data/Datasets/CASIA/test'


def is_left(file_name):
    return file_name.find('_l_')


def get_pid(file_name):
    return int(file_name[:4])


def get_iid(file_name):
    return int(file_name[-5:-4])


def cp(path_a, file_a, path_b, file_b=None):
    if file_b is None:
        file_b = file_a
    copyfile(os.path.join(path_a, file_a), os.path.join(path_b, file_b))


if __name__ == '__main__':
    num_iid = 312
    th = num_iid / 2
    files_1 = os.listdir(input_1)
    for ifile in files_1:
        if get_pid(ifile) <= th:
            cp(input_1, ifile, out_train)
        else:
            cp(input_1, ifile, out_test)
